<template>
    <div id="content-reply">
        <div class="reply">
          <div>
            <img class="install-headerimg" v-if="item.userHeadImage" :src="item.userHeadImage" />
            <img class="install-headerimg" v-else src="../../../static/img/installheaderimg.jpg" />
          </div>
          <div>
            <p>{{item.userName}}</p>
            <p>{{item.title}}</p>
          </div>
          <p class="clear"></p>
        </div>
        <div class="circle"></div>
        <group>
        <x-textarea v-model="value"  name="detail" :placeholder="'回复'" :max="200" :show-counter="false"  :rows="8" :cols="30"></x-textarea>
      </group>
      <div class="desc-reply">
        <p>认真的回答更容易肥家到他们的认可哦~（2000字以内）</p>
        <p>1、用自己的【真实经右】作答；</p>
        <p>2、尽量【分条回答】，逻辑清晰；</p>
      </div>
      <div class="share" @click="issue">发布</div>
    </div>
</template>
<script>
var timeStamp = String(Number(new Date()))
import { XTextarea, Group } from 'vux'
import api from '../../api'
import utils from '../../utils'
export default {
  data () {
    return {
      item: {},
      value: '',
      tokenval: ''
    }
  },
  components: {
    XTextarea,
    Group
  },
  created () {
    window.document.title = '回复'
    this.tokenval = utils.AuthToken(timeStamp, this.$store.state.userkey)
    var params = {
      Tokenuser: this.tokenval,
      userid: this.$store.state.userID,
      timestamp: timeStamp,
      id: utils.getQueryString('circle_id')
    }
    api.contentdetail(params).then(res => {
      console.log(res)
      if (res.status === 200) {
        this.item = res.data
      } else {
        this.$vux.toast.show({
          text: res.message,
          type: 'warn',
          width: '4rem'
        })
      }
    })
    utils.jssdkwx(api, this.$wechat, this.$store)
  },
  methods: {
    issue () {
      if (this.value === '') {
        this.$vux.toast.show({
          text: '请输入回复内容',
          type: 'warn',
          width: '4rem'
        })
      } else if (this.value.length === 200) {
        this.$vux.toast.show({
          text: '回复在200个字以内',
          type: 'warn',
          width: '4rem'
        })
      } else {
        api.topictreply({
          token: this.tokenval,
          timestamp: timeStamp,
          userId: this.$store.state.userID,
          topicId: utils.getQueryString('circle_id'),
          content: this.value
        }).then(res => {
          console.log(res)
          if (res.status === 200) {
            this.$router.push('/circle/index')
          } else {
            this.$vux.toast.show({
              text: res.message,
              type: 'warn',
              width: '4rem'
            })
          }
        })
      }
    }
  }
}
</script>
